package com.j.lemon.learn.thread.lock;

import java.util.concurrent.Semaphore;

/**
 * @Author lijunjun
 * @Date 2019-04-22 14:12
 * @Description
 */
public class SemaPhoreDemo {
    Semaphore semaphore = new Semaphore(1);

    public void wait1() throws InterruptedException {
        semaphore.acquire();
        System.out.println(Thread.currentThread().getName()+"进入门店吃饭");
        Thread.sleep(2000);
        semaphore.release();
        System.out.println(Thread.currentThread().getName()+"吃完走人");
    }

    public static void main(String[] args) {
        SemaPhoreDemo semaPhoreDemo = new SemaPhoreDemo();
        for (int i = 0; i < 32; i++) {
            new Thread(()->{
                try {
                    semaPhoreDemo.wait1();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            },String.valueOf(i)).start();
        }
    }
}
